﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class fileControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        DropDownList selectdown;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            selectdown = (DropDownList)FindControl("selectdown");
            if (base.Page.Request["action"] == "del" && base.Page.Request["id"] != null)
            {
                bool del = _EluZSDataProvider.DeleteXmByID("zs_file", "id", base.Page.Request["id"]);
            }
            if (!base.Page.IsPostBack)
            {
                DataTable dt = _EluZSDataProvider.GetXMName();
                selectdown.DataSource = dt;
                selectdown.DataTextField = "项目名称";
                selectdown.DataValueField = "ITEMID";
                selectdown.DataBind();
                Bind();
            }
            if (!string.IsNullOrEmpty(base.Page.Request["itemid"]))
            {
                int t1 = Convert.ToInt32(_EluZSDataProvider.GetSomeStr("zs_file", "count(*)", "itemid", base.Page.Request["itemid"]));
                if (t1 > 0) 
                {
                    selectdown.SelectedValue = base.Page.Request["itemid"];
                    Bind();
                }
            }
            selectdown.SelectedIndexChanged += new EventHandler(selectdown_SelectedIndexChanged);
        }
        protected void Bind()
        {
            MPRepeater MPRepeaterList = (MPRepeater)FindControl("MPRepeaterList");
            DataTable dt = _EluZSDataProvider.GetFileControl(selectdown.SelectedValue);
            MPRepeaterList.DataSource = dt;
            MPRepeaterList.DataBind();
        }
        protected void selectdown_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bind();
        }
    }
}


